package com.hmis.dao;

import com.hmis.domain.Clinic;
import com.hmis.service.ClinicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
@Controller
public class ClinicDAO implements InitializingBean {

    public static ClinicService clinicService;
    public static ClinicDAO clinicDAO;
    private Map<String, String> doc_dep_map = new HashMap<>();
    @Autowired
    private ClinicService clinic;

    public List<Clinic> listClinic() {
        return clinicService.list();
    }

    private void setMap() {
        List<Clinic> clinicList = listClinic();
        for (Clinic clinic : clinicList) {
            doc_dep_map.put(clinic.getDutyDoctor(), clinic.getDeptName());
        }
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        clinicService = clinic;
        clinicDAO = this;
        setMap();
    }

    public Map<String, String> getDoc_dep_map() {
        return doc_dep_map;
    }

}
